package com.example.wmuqrreader;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class BuildingActivity extends Activity {

	Button button_save; 
	
	Bundle extras;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_building);
		
		button_save = (Button) findViewById(R.id.btn_save);
		extras 		= getIntent().getExtras();
		
		//Add a function for the SAVE button click
        button_save.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {	
				
				//If exists, update, else add
				if (extras.getString("ID") != null )
				{
					//db.updateInventory( populateInventory( Integer.parseInt(extras.getString("ID")) ) );		
					Toast.makeText(getApplicationContext(), "Changes saved successfully", Toast.LENGTH_LONG).show();
				}
				else
				{
					//db.addInventory( populateInventory(0) );		
					Toast.makeText(getApplicationContext(), "New entry added to the database", Toast.LENGTH_LONG).show();
				}
				
				setResult(RESULT_OK, null);
				finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.building, menu);
		return true;
	}

}
